/**
* \file serializer.h
* \brief Declaration of the Serializer class
* \date 23/09/2009
* \author Jérôme Stadelmann, Reds, Heig-vd
*/

#ifndef SERIALIZER_H
#define SERIALIZER_H

#include <QObject>
#include <QFile>
#include <QTextStream>
#include <QMutex>



/// This class helps to log data into some files
class Serializer : public QObject
{
    Q_OBJECT

public:
    /// Constructor
    Serializer(const QString& fileName);

    /// Destructor
    virtual ~Serializer();

    /// print in the file the values of the command and sample numers
    void logSampleNBR(int nbCurrentCommand, int nbCurrentSample);
    /// print in the file the values for one axe of a sample command
    void logSampleData(double* data, int points);

    /// Serializes a set of data to the file
    void        writeDataSet(short* data, int points);

    /// Serializes a set of data to the file
    void        writeDataSet(float* data, int points);

    /// Adds a line separator to the file
    void        writeSeparator();

    /// Clears the current file
    void        clear();

    /// Closes the current file
    void        close();

    /// Opens a new file
    void        open(const QString& fileName);

    /// Save the file to another name
    QString     saveTo(const QString& fileName);

    /// Gets the current file name
    QString     getFileName();

    /// Get the next free file name (adds a counter suffix for this)
    QString     getNextFileName(const QString& fileName);





private:

    QFile           m_file;
    QTextStream     m_stream;
    QMutex m_hMutex;
};

#endif // SERIALIZER_H
